-- light_damage
-- create by panyl
-- 光元素球，对目标施加伤害

return {
    apply = function(source, target, skillId, round, para, extra)
        -- 贤者之语id
        local id = para[1];
        local stoneData = source.dbase:query("stone", {});
        local level = stoneData[id] or 0;

        local magic = source:getMagic();
        local force = math.min(1000 + level * 200, 2000 + level * 100, 3500 + level * 50)
        local damage = math.modf((magic + 3) * force / 1000);

        damage = math.max(damage, 1);

        -- 状态加成
        local addonRate = 0;
        local prop = PropM.combine(source, "magic_effect", skillId);
        addonRate = addonRate + PropM.apply(prop, 1);

        if #para > 1 and target:query("base_class_id") == para[2] then
            -- 加成
            addonRate = addonRate + para[3] - 1000;
        end

        -- 最终效果
        damage = math.modf(damage * (addonRate + 1000) / 1000);

        -- 增加命中动作
        SkillM.getSequence(target):hit(source, target, skillId);

        -- 伤害
        CombatM.receiveDamage(source, target, damage, skillId, extra);

        -- 作用目标
        return { target, };
    end,

    parse = function(desc)
        local arr = string.explode(desc, ",");
        if #arr == 1 then
            return { tonumber(arr[1]), };
        else
            return { tonumber(arr[1]), tonumber(arr[2]), tonumber(arr[3]), }
        end
    end,

    -- 解析技能描述
    parseDesc = function(source, skillId, desc, para)
        local id = para[1];
        local stoneData = source.dbase:query("stone", {});
        local level = stoneData[id] or 0;

        local magic = source:getMagic();
        local force = math.min(1000 + level * 200, 2000 + level * 100, 3500 + level * 50)
        local damage = math.modf((magic + 3) * force / 1000);

        damage = math.max(damage, 1);

        -- 状态加成
        local addonRate = 0;
        local prop = PropM.combine(source, "magic_effect", skillId);
        addonRate = addonRate + PropM.apply(prop, 1);
        -- 加成效果
        local damageAddon = math.modf(damage * addonRate / 1000);

        if damageAddon == 0 then
            desc = string.gsub(desc, "{light_damage}", damage);
        else
            desc = string.gsub(desc, "{light_damage}", damage .. "(+" .. damageAddon .. ")");
        end

        return desc;
    end,
};
